import log from "./logger";
import axios from "axios";
import * as moment from "moment";

const ADODB = require('node-adodb');

const year = moment(Date.now()).format('YYYY');
const month = moment(Date.now()).format('M');
const connection2 = ADODB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.1.133\\本地磁盘 (d)\\GCU\\db\\' + year + '.db;');
//query操作的是有返回量的，比如查询
setInterval(() => {
    connection2.query(' select m.序号 as serial_number, m.时间 as fy_time, m.轨道衡测点 as dedicated_line, ' +
        'm.车号 as carriage_number, m.车型 as models, m.毛重 as gross_weight, m.皮重 as tare_weight, m.净重 as net_weight, m.标重 as load_weight, m.速度 as speeds ' +
        'from ' + month + ' m where m.时间 in (select top 10 日期_时间 from VHICLECATALOG where 方向 = "→" and 传送标志 = 4352 order by 日期_时间 desc)').then((data: any) => {
        const a = []
        data.forEach((item: any) => {
            const b = {
                serialNumber: item.serial_number,
                fyTime: item.fy_time,
                dedicatedLine: item.dedicated_line,
                carriageNumber: item.carriage_number,
                model: item.models,
                grossWeight: item.gross_weight,
                tareWeight: item.tare_weight,
                netWeight: item.net_weight,
                loadWeight: item.load_weight,
                speed: item.speeds,
            }
            a.push(b)
        });
        console.log(month)
        a.push({type: 'hh_sz'})
        console.log(a)
        //http://localhost:8765/depatch/platform/fy/getFyData
        //http://py.wechain360.com/api/depatch/platform/fy/getFyData
        //http://platform.wechain360.com/api/depatch/platform/fy/getFyData
        axios.post('http://platform.wechain360.com/api/depatch/platform/fy/getFyData', a, {headers: {"platformId": 15}}).then((response) => {
            console.log(response.data);
        }).catch((e: any) => {
            log.error(e);
        })
    }).catch((err: any) => {
        console.log(err);
    })
}, 50000);